package net.opentsdb.core;

import org.hbase.async.Bytes;

/**
 * @author Hujf
 * @title: Internal
 * @date 2021-09-22 14:56
 * @description: TODO
 */
public class Internal {



    public static byte[] buildQualifier(long timestamp, short flags) {
        final long base_time;
        if ((timestamp & Const.SECOND_MASK) != 0) {
            base_time = ((timestamp / 1000) - ((timestamp / 1000)
                    % Const.MAX_TIMESPAN));
            final int qual = (int) (((timestamp - (base_time * 1000)
                    << (Const.MS_FLAG_BITS)) | flags) | Const.MS_FLAG);
            return Bytes.fromInt(qual);
        }else{
            base_time = (timestamp - (timestamp % Const.MAX_TIMESPAN));
            final short qual = (short) ((timestamp - base_time) << Const.FLAG_BITS
                    | flags);
            return Bytes.fromShort(qual);
        }
    }
}
